package com.yiwei.zxp.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.BussinessOrderDetailActivity;
import com.yiwei.zxp.activity.BuyerOrderDetailActivity;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class OrderPhotoAdapter extends ItemAdapter<String, OrderPhotoAdapter.DefaultHolder> {


    private Context context;
    private String order_no;
    private boolean isBuyer = false;

    public void setOrder_no(String order_no) {
        this.order_no = order_no;
    }

    public OrderPhotoAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_order_photo, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        Glide.with(context).load(getItem(position)).into(holder.imgGoods);
        holder.imgGoods.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isBuyer) {
                    Intent intent = new Intent(context, BuyerOrderDetailActivity.class);
                    intent.putExtra("order_no", order_no);
                    context.startActivity(intent);
                } else {
                    Intent intent = new Intent(context, BussinessOrderDetailActivity.class);
                    intent.putExtra("order_no", order_no);
                    context.startActivity(intent);
                }

            }
        });
    }

    public void setType(boolean isBuyer) {
        this.isBuyer = isBuyer;
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_goods)
        ImageView imgGoods;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
